package com.sugar.queryinfo.module.business.dal.mysql.tffinance;

import java.util.*;

import com.sugar.queryinfo.framework.common.pojo.PageResult;
import com.sugar.queryinfo.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.sugar.queryinfo.framework.mybatis.core.mapper.BaseMapperX;
import com.sugar.queryinfo.module.business.dal.dataobject.tffinance.TfFinanceDO;
import org.apache.ibatis.annotations.Mapper;
import com.sugar.queryinfo.module.business.controller.admin.tffinance.vo.*;
import org.apache.ibatis.annotations.Update;

/**
 * 真假财务 Mapper
 *
 * @author Ysugar
 */
@Mapper
public interface TfFinanceMapper extends BaseMapperX<TfFinanceDO> {

    default PageResult<TfFinanceDO> selectPage(TfFinancePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TfFinanceDO>()
                .eqIfPresent(TfFinanceDO::getName, reqVO.getName())
                .eqIfPresent(TfFinanceDO::getRiskType, reqVO.getRiskType())
                .betweenIfPresent(TfFinanceDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TfFinanceDO::getId));
    }

    @Update("<script>" +
            "<foreach item=\"name\" collection=\"names\" open=\"BEGIN\" close=\"END\" separator=\";\"> " +
            "  update business_tf_finance btf " +
            "  set btf.query_count = btf.query_count + 1 " +
            "  where btf.name = #{name} " +
            "<if test=\"param2 != null\"> and btf.risk_type = #{param2}</if>" +
            "</foreach>" +
            "</script>")
    void updateQueryCountByNames(List<String> names, Integer riskType);

    @Update("<script>" +
            "update business_tf_finance btf " +
            "set btf.query_count = btf.query_count + 1 " +
            "where btf.name = #{param1} " +
            "<if test=\"param2 != null\"> and btf.risk_type = #{param2}</if>" +
            "</script>")
    void updateQueryCount(String name, Integer riskType);
}